package it.asvp.asvp_portal.asvp_util.util;

import java.util.Calendar;
import java.util.Date;

public class DateUtils {

	
	public static Date getCurrentDate(){
		return new java.sql.Date(new java.util.Date().getTime());
	}
	
    public static int compare(final Date date1, final Date date2, final boolean time) {
		
		if (date1 == null || date2 == null) {
			throw new IllegalArgumentException("Date non valide");
		}
		
		final Calendar c1 = Calendar.getInstance();
		c1.setTime(date1);
		
		final Calendar c2 = Calendar.getInstance();
		c2.setTime(date2);
		
		if (time==false) {
			//non vengono considerati: ora,minuti,secondi e millisecondi
			c1.set(Calendar.HOUR_OF_DAY, 0);
			c1.set(Calendar.MINUTE, 0);
			c1.set(Calendar.SECOND, 0);
			c1.set(Calendar.MILLISECOND, 0);
			
			c2.set(Calendar.HOUR_OF_DAY, 0);
			c2.set(Calendar.MINUTE, 0);
			c2.set(Calendar.SECOND, 0);
			c2.set(Calendar.MILLISECOND, 0);
		}
		
		if(c1.before(c2)) {
			return -1;
		} else {
			if(c1.after(c2))
				return 1;
			else
				return 0;
		}
	}
    
    public int getDiffDays(Date date1,Date date2){
    	
    	long millisDiff = date1.getTime() - date2.getTime();
    	int days = (int) (millisDiff / 86400000);
    	return days;
    }
}
